import Vue from 'vue'
import VueRouter  from 'vue-router'
 
Vue.use(VueRouter);
 
import TenYearOf from '@/pages/TenYearOf'
import BlogHome from '@/pages/BlogHome'
import Choice from '@/pages/Choice'
import RegisterAndLogin from '@/pages/RegisterAndLogin'
import MainLook from '@/pages/MainLook'
import Detail from '@/pages/Detail'
import PersonalCenter from '@/pages/PersonalCenter'
import PHome from '@/pages/PersonalCenter/PHome'
import PDetail from '@/pages/PersonalCenter/PDetail'
import PStart from '@/pages/PersonalCenter/PStart'
import PWrite from '@/pages/PersonalCenter/PWrite'
import PSgs from '@/pages/PersonalCenter/PSgs'
import BasicMessage from '@/pages/PersonalCenter/PHome/BasicMessage'
import ChangePassword from '@/pages/PersonalCenter/PHome/ChangePassword'
import HeadSet from '@/pages/PersonalCenter/PHome/HeadSet'
import YI from '@/pages/PersonalCenter/PHome/YI'
import NoLogin from '@/pages/NoLogin'
import oneRoom from '@/pages/oneRoom'
import midTime from '@/pages/midTime'
import Edit from '@/pages/Edit'

import { getCookie } from '@/utils';

const router =  new VueRouter({
    // mode:'history',
    scrollBehavior (to, from, savedPosition) {
        if(!(to.fullPath.startsWith('/PersonalCenter') && from.fullPath.startsWith('/PersonalCenter'))){
            return {x:0,y:0}
        }
    },
    routes:[
        //在此处写你的路由配置
        // {
        //     path:'/PWrite',
        //     name:'PWrite',
        //     component:PWrite, 
        // },
        {
            path:'/oneRoom',
            name:'oneRoom',
            component:oneRoom,
            props($route){
                return {title:$route.query.title}
            }
        },
        {
            path:'/TenYearOf/:from?',
            name:'TenYearOf',
            component:TenYearOf
        },
        {
            path:'/BlogHome',
            name:'BlogHome',
            component:BlogHome
        },
        {
            path:'/Choice',
            name:'Choice',
            component:Choice
        },
        //注册页面
        {
            path:'/RegisterAndLogin',
            name:'RegisterAndLogin',
            component:RegisterAndLogin
        },
        //detail列表总
        {
            path:'/MainLook',
            name:'MainLook',
            component:MainLook,
        },
        //详情
        {
            path:'/Detail',
            name:'Detail',
            component:Detail,
            props($route){
                return {article_id:$route.query.id,floor:$route.query.floor}
            }
        },
        //个人中心
        {
            path:'/PersonalCenter',
            name:'PersonalCenter',
            component:PersonalCenter,
            beforeEnter:(to,from,next)=>{
                let obj = getCookie()
                for(let key in obj){
                    if(obj[key] == 'true' && key == 'IfLogin'){
                        return next();
                    }
                }
                next('/noLogin')
            },
            children:[
                {
                    path:'PHome',
                    name:'PHome',
                    component:PHome, 
                    children:[
                        {
                            path:'BasicMessage',
                            name:'BasicMessage',
                            component:BasicMessage, 
                        },
                        {
                            path:'ChangePassword',
                            name:'ChangePassword',
                            component:ChangePassword, 
                        },
                        {
                            path:'HeadSet',
                            name:'HeadSet',
                            component:HeadSet, 
                        },
                        {
                            path:'YI',
                            name:'YI',
                            component:YI, 
                        },
                    ]
                },
                {
                    path:'PDetail',
                    name:'PDetail',
                    component:PDetail, 
                },
                {
                    path:'PStart',
                    name:'PStart',
                    component:PStart, 
                },                {
                    path:'PWrite',
                    name:'PWrite',
                    component:PWrite, 
                },               
                {
                    path:'PSgs',
                    name:'PSgs',
                    component:PSgs, 
                },
            ]
        },
        {
            path:'/Edit',
            name:'Edit',
            component:Edit,
            props($route){
                return {article_id:$route.query.id}
            },
            // beforeEnter:(to,from,next)=>{
            //     let obj = getCookie()
            //     for(let key in obj){
            //         if(obj[key] == 'true' && key == 'IfLogin'){
            //             return next();
            //         }
            //     }
            //     next('/noLogin')
            // },
        },
        {
            path:'/noLogin',
            name:'noLogin',
            component:NoLogin
        },
        {
            path:'/midTime',
            name:'midTime',
            component:midTime,
        },
        {
            path:'/',
            redirect:"/Choice"
        }
    ]
})

export default router
